package models

func GetAllEmployeeInformation() ([]EmployeeInfo, error) {
	res, err := Db.Query("SELECT * FROM worker_transfer_informations.employees")
	CheekErr(err)
	resc := make([]EmployeeInfo, 0)
	i := 0
	for res.Next() {
		resc = append(resc, EmployeeInfo{})
		err := res.Scan(&resc[i].Id, &resc[i].Name, &resc[i].Status, &resc[i].ArriveDate, &resc[i].Job, &resc[i].Position, &resc[i].DepartmentID)
		if err != nil {
			return nil, err
		}
		i++
	}
	_ = res.Close()
	return resc, nil;
}
func GetAllTransInformation() ([]TransferInfo, error) {
	res, err := Db.Query("SELECT * FROM worker_transfer_informations.transfer_informations")
	CheekErr(err)
	resc := make([]TransferInfo, 0)
	i := 0
	for res.Next() {
		resc = append(resc, TransferInfo{})
		err := res.Scan(&resc[i].Id, &resc[i].WorkId, &resc[i].TransDate, &resc[i].InDep, &resc[i].OutDep, &resc[i].Why)
		if err != nil {
			return nil, err
		}
		i++
	}
	_ = res.Close()
	return resc, nil;
}
func GetAllDepInformation() ([]DepartmentInfo, error) {
	res, err := Db.Query("SELECT * FROM worker_transfer_informations.departments")
	CheekErr(err)
	resc := make([]DepartmentInfo, 0)
	i := 0
	for res.Next() {
		resc = append(resc, DepartmentInfo{})
		err := res.Scan(&resc[i].DepartmentID, &resc[i].Name)
		if err != nil {
			return nil, err
		}
		i++
	}
	_ = res.Close()
	return resc, nil;
}
